package com.yudean.esb.service.impl.mds;

import com.yudean.esb.domain.mds.MdsERPFinIndex;
import com.yudean.esb.mapper.mds.MdsERPFinIndexMapper;
import com.yudean.esb.service.MdsERPFinIndexService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Scope("prototype")
public class MdsERPFinIndexServiceImpl implements MdsERPFinIndexService {
    @Resource
    private MdsERPFinIndexMapper mdsERPFinIndexMapper;

    /**
     * 已经通过数据层屏蔽掉差异。通过mdsIndex即可判断查询那些条件
     *
     * @param mdsIndex
     * @return
     */
    @Override
    public List<MdsERPFinIndex> findIndex(MdsERPFinIndex mdsIndex) {
        if (mdsIndex == null) {
            return null;
        }
        List<MdsERPFinIndex> list = mdsERPFinIndexMapper.findIndex(mdsIndex);
        if (list == null || list.size() < 1) {
            return null;
        }
        return list;
    }

    /**
     * 获取今年的数据
     *
     * @param mdsIndex
     * @return
     */
    @Override
    public List<MdsERPFinIndex> getThisYear(MdsERPFinIndex mdsIndex) {
        if (null == mdsIndex) {
            return null;
        }
        List<MdsERPFinIndex> list = mdsERPFinIndexMapper
                .getThisYearData(mdsIndex);
        if ((null == list) || (list.size() < 1)) {
            return null;
        }
        return list;
    }

    /**
     * 获得去年存在数据的最大月份
     *
     * @param year 年份
     * @return
     */
    @Override
    public Integer getLastMaxMonth(Integer year) {
        Integer result = mdsERPFinIndexMapper.getLastMaxMonth(year);
        return result == null ? 12 : result;
    }
}